package com.wanxi.controller;

import com.wanxi.model.Message;
import com.wanxi.model.User;
import com.wanxi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Message login(User user) {
        return userService.login(user);
    }

    @PostMapping("/getUserList")
    public Message<User> getUserList(@RequestParam Map<String, Object> map) {
        return userService.getUserList(map);
    }

    @GetMapping("/getUserById")
    public User getUserById(@RequestParam Integer id) {
        return userService.getUserById(id);
    }

    @PostMapping("/addUser")
    public int addUser(User user) {
        return userService.addUser(user);
    }

    @PostMapping("/getUserByUsername")
    public Message getUserByUsername(String username) {
        return userService.getUserByUsername(username);
    }

    @GetMapping("/getUserByTeam")
    public List<User> getUserByTeam(String team) {
        return userService.getUserByTeam(team);
    }

    @PostMapping("/editUser")
    public int editUser(@RequestParam Map map) {
        return userService.editUser(map);
    }

    @PostMapping("/updateUserTeam")
    public int updateUserTeam(@RequestParam Map map) {
        return userService.updateUserTeam(map);
    }
    @PostMapping("/updateStatus")
    public int updateStatus(@RequestParam Map map){
        return userService.updateStatus(map);
    }

    @PostMapping("/deleteUsers")
    public int deleteUsers(@RequestParam Map map){
        return userService.deleteUsers(map);
    }
    @GetMapping("/exit")
    public void exit(HttpServletRequest req) {
        HttpSession session = req.getSession();
        session.invalidate();
    }
}
